package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.SitesTypeService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.SitesType;

/**
 * Created by fenglibin on 2018/11/15.
 */
@Controller
@RequestMapping("/sitesType/")
public class SitesTypeController {

    @Autowired
    SitesTypeService sitesTypeService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<SitesType>> selectAll() {
        return Result.success(sitesTypeService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<SitesType> selectByPrimaryKey(Integer id) {
        return Result.success(sitesTypeService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<SitesType>> selectByCondition(SitesType record) {
        return Result.success(sitesTypeService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(SitesType record) {
        return Result.success(sitesTypeService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(SitesType record) {
        return Result.success(sitesTypeService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(SitesType record) {
        return Result.success(sitesTypeService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<SitesType>>> selectByPage(Page<SitesType> page) {
        List<SitesType> list = null;
        page = page.sequentialDisplayCalculate(sitesTypeService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = sitesTypeService.selectByPage(page);
        }
        Page<List<SitesType>> result = new Page<List<SitesType>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(SitesType record) {
        return Result.success(sitesTypeService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id) {
        return Result.success(sitesTypeService.deleteByPrimaryKey(id));
    }

}
